package com.baima46.core;

import com.baima46.model.ExcelInfo;
import com.baima46.model.HeaderCell;
import com.baima46.model.SheetInfo;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @Description excel导出信息处理
 * @Author yuan cong
 * @Date 2020/12/7 0007
 */
public class InfoHandle {

    public static ExcelInfo getInfo(String excelName, List<?> dataList, Class<?> dataClass, String... group) {
        //excel导出信息
        ExcelInfo excelInfo = new ExcelInfo();
        excelInfo.setFileName(excelName);

        //sheet页信息
        SheetInfo sheet1 = getSheetInfo("sheet1", dataList, dataClass, group);
        excelInfo.setSheetList(Collections.singletonList(sheet1));

        return excelInfo;
    }

    public static SheetInfo getSheetInfo(String sheetName, List<?> dataList, Class<?> dataClass, String... group) {
        //sheet页信息
        SheetInfo sheetInfo = new SheetInfo(sheetName, dataList, dataClass, Arrays.asList(group));

        //将坐标转换为HeaderCell对象集合
        List<HeaderCell> headerCellList = HeaderHandle.getHeaderCellList(sheetInfo);
        sheetInfo.setHeaderCellList(headerCellList);

        //解析数据内容集合
        List<List<Object>> rowList = null;
        try {
            rowList = DataHandle.getData(sheetInfo);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
            throw new RuntimeException("数据解析异常！");
        }
        sheetInfo.setRowList(rowList);

        return sheetInfo;
    }
}
